﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Kangaroo.DAL.SqlServer;
using Kangaroo.DAL.SqlServer.Tests;
using Kangaroo.Model.Tests;
using NUnit.Framework;

namespace Kangaroo.Shell.Tests
{
    [TestFixture]
    public class DataGen
    {
        private static readonly Random _random = new Random();

// ReSharper disable InconsistentNaming
// ReSharper disable NotAccessedField.Local
        private static IEnumerable<DateTime> TimePoints;
// ReSharper restore NotAccessedField.Local
// ReSharper restore InconsistentNaming

// ReSharper disable UnusedMember.Local
        private static IEnumerable<byte[]> GraphData
// ReSharper restore UnusedMember.Local
        {
            get { yield return PrpsGraphDataGen.Generate(_random); }
        }

        static DataGen()
        {
            var baseTime = DateTime.Parse("2012/4/23");
            var pdTimes = new[]
            {
                baseTime,
                baseTime.AddHours(1),
                baseTime.AddDays(1.1),
                baseTime.AddDays(1.3)
            };
            TimePoints = pdTimes;
        }

        [TestFixtureSetUp]
        public void FixtureSetup()
        {
            SqlHelper.ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=Kangaroo;Integrated Security=True;";
            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, @"DELETE FROM PDTable");
            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, @"DELETE FROM ChannelTable");
            SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.Text, @"DELETE FROM AlarmTable");
        }

        [Test, Combinatorial]
        public void GeneratePd(
            [Values("检测装置1", "检测装置2")]
            string devId,
            [Values(0, 1, 2)]
            short devChn,
            [Values("电力设备1", "电力设备2")]
            string equipId,
            [Range(1, 7)]
            byte equipPhase,
            [ValueSource("TimePoints")]
            DateTime pdTime,
            [Values(.5F)]
            float pdMean,
            [Values(1.1F)]
            float pdMax,
            [Values(0.3F)]
            float pdPhase,
            [Values(1000F)]
            float pdRep,
            [Values("pdType1")]
            string pdType,
            [Values("pdTypeProb1")]
            string pdTypeProb,
            [Values("pdLoc1")]
            string pdLoc,
            [Values("pdLevel1")]
            string pdLevel,
            [Values("pdFile1")]
            string pdFile,
            [ValueSource("GraphData")]
            byte[] prpsGraph)
        {
            DalTestHelper.CreateSignal(devId, devChn, equipId, equipPhase,
                pdTime, pdMean, pdMax, pdPhase, pdRep, pdType,
                pdTypeProb, pdLoc, pdLevel, pdFile, prpsGraph);
        }
    }
}
